﻿using System; 
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic; 
using System.Data;

namespace Sasc.PV.DAL
{
		/// <summary>
	/// PvZDShaoJieYunXing
	/// </summary>
		public partial class PvZDShaoJieYunXing:IPVDomain
	{ 
		#region Fields
	    	private long _id;		
		/// <summary>
		/// ID
        /// </summary>		
        public long ID
        {
            get{ return _id; }
            set{ _id = value; }
        }        
			private DateTime _shaojieyuxingdate;		
		/// <summary>
		/// ShaoJieYuXingDate
        /// </summary>		
        public DateTime ShaoJieYuXingDate
        {
            get{ return _shaojieyuxingdate; }
            set{ _shaojieyuxingdate = value; }
        }        
			private decimal _axiangdianya;		
		/// <summary>
		/// AXiangDianYa
        /// </summary>		
        public decimal AXiangDianYa
        {
            get{ return _axiangdianya; }
            set{ _axiangdianya = value; }
        }        
			private decimal _axiangdianliu;		
		/// <summary>
		/// AXiangDianLiu
        /// </summary>		
        public decimal AXiangDianLiu
        {
            get{ return _axiangdianliu; }
            set{ _axiangdianliu = value; }
        }        
			private decimal _bxiangdianya;		
		/// <summary>
		/// BXiangDianYa
        /// </summary>		
        public decimal BXiangDianYa
        {
            get{ return _bxiangdianya; }
            set{ _bxiangdianya = value; }
        }        
			private decimal _bxiangdianliu;		
		/// <summary>
		/// BXiangDianLiu
        /// </summary>		
        public decimal BXiangDianLiu
        {
            get{ return _bxiangdianliu; }
            set{ _bxiangdianliu = value; }
        }        
			private decimal _cxiangdianya;		
		/// <summary>
		/// CXiangDianYa
        /// </summary>		
        public decimal CXiangDianYa
        {
            get{ return _cxiangdianya; }
            set{ _cxiangdianya = value; }
        }        
			private decimal _cxiangdianliu;		
		/// <summary>
		/// CXiangDianLiu
        /// </summary>		
        public decimal CXiangDianLiu
        {
            get{ return _cxiangdianliu; }
            set{ _cxiangdianliu = value; }
        }        
			private decimal _yihaotongdaotemp;		
		/// <summary>
		/// YiHaoTongDaoTemp
        /// </summary>		
        public decimal YiHaoTongDaoTemp
        {
            get{ return _yihaotongdaotemp; }
            set{ _yihaotongdaotemp = value; }
        }        
			private decimal _erhaotongdaotemp;		
		/// <summary>
		/// ErHaoTongDaoTemp
        /// </summary>		
        public decimal ErHaoTongDaoTemp
        {
            get{ return _erhaotongdaotemp; }
            set{ _erhaotongdaotemp = value; }
        }        
			private decimal _sanhaotongdaotemp;		
		/// <summary>
		/// SanHaoTongDaoTemp
        /// </summary>		
        public decimal SanHaoTongDaoTemp
        {
            get{ return _sanhaotongdaotemp; }
            set{ _sanhaotongdaotemp = value; }
        }        
			private long _shaojiecollectionid;		
		/// <summary>
		/// ShaoJieCollectionID
        /// </summary>		
        public long ShaoJieCollectionID
        {
            get{ return _shaojiecollectionid; }
            set{ _shaojiecollectionid = value; }
        }        
			private DateTime _lastupdateddate;		
		/// <summary>
		/// LastUpdatedDate
        /// </summary>		
        public DateTime LastUpdatedDate
        {
            get{ return _lastupdateddate; }
            set{ _lastupdateddate = value; }
        }        
			private string _lastupdatedby;		
		/// <summary>
		/// LastUpdatedBy
        /// </summary>		
        public string LastUpdatedBy
        {
            get{ return _lastupdatedby; }
            set{ _lastupdatedby = value; }
        }        
		   		#endregion
   		
   		#region DAL Methods
		public bool Exists(long ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from PvZDShaoJieYunXing");
			strSql.Append(" where ");
			                                       strSql.Append(" ID = @ID  ");
                            			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.BigInt)
			};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}
		
		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add()
		{
          return  Add(this);
		}
				
		
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add(PvZDShaoJieYunXing model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into PvZDShaoJieYunXing(");			
            strSql.Append("ShaoJieYuXingDate,AXiangDianYa,AXiangDianLiu,BXiangDianYa,BXiangDianLiu,CXiangDianYa,CXiangDianLiu,YiHaoTongDaoTemp,ErHaoTongDaoTemp,SanHaoTongDaoTemp,ShaoJieCollectionID,LastUpdatedDate,LastUpdatedBy");
			strSql.Append(") values (");
            strSql.Append("@ShaoJieYuXingDate,@AXiangDianYa,@AXiangDianLiu,@BXiangDianYa,@BXiangDianLiu,@CXiangDianYa,@CXiangDianLiu,@YiHaoTongDaoTemp,@ErHaoTongDaoTemp,@SanHaoTongDaoTemp,@ShaoJieCollectionID,@LastUpdatedDate,@LastUpdatedBy");            
            strSql.Append(") ");            
            strSql.Append(";select @@IDENTITY");		
			SqlParameter[] parameters = {
			            new SqlParameter("@ShaoJieYuXingDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@AXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@BXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@BXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@YiHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ErHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@SanHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShaoJieCollectionID", SqlDbType.BigInt,8) ,            
                        new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@LastUpdatedBy", SqlDbType.NVarChar,200)             
              
            };
			            
            parameters[0].Value = model.ShaoJieYuXingDate;                        
            parameters[1].Value = model.AXiangDianYa;                        
            parameters[2].Value = model.AXiangDianLiu;                        
            parameters[3].Value = model.BXiangDianYa;                        
            parameters[4].Value = model.BXiangDianLiu;                        
            parameters[5].Value = model.CXiangDianYa;                        
            parameters[6].Value = model.CXiangDianLiu;                        
            parameters[7].Value = model.YiHaoTongDaoTemp;                        
            parameters[8].Value = model.ErHaoTongDaoTemp;                        
            parameters[9].Value = model.SanHaoTongDaoTemp;                        
            parameters[10].Value = model.ShaoJieCollectionID;                        
            parameters[11].Value = model.LastUpdatedDate;                        
            parameters[12].Value = model.LastUpdatedBy;                        
			   
			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);			
			if (obj == null)
			{
				return 0;
			}
			else
			{
				                                    
            	return Convert.ToInt64(obj);
                                                  
			}			   
            			
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			return Update(this);
		}
		
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(PvZDShaoJieYunXing model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update PvZDShaoJieYunXing set ");
			                                                
            strSql.Append(" ShaoJieYuXingDate = @ShaoJieYuXingDate , ");                                    
            strSql.Append(" AXiangDianYa = @AXiangDianYa , ");                                    
            strSql.Append(" AXiangDianLiu = @AXiangDianLiu , ");                                    
            strSql.Append(" BXiangDianYa = @BXiangDianYa , ");                                    
            strSql.Append(" BXiangDianLiu = @BXiangDianLiu , ");                                    
            strSql.Append(" CXiangDianYa = @CXiangDianYa , ");                                    
            strSql.Append(" CXiangDianLiu = @CXiangDianLiu , ");                                    
            strSql.Append(" YiHaoTongDaoTemp = @YiHaoTongDaoTemp , ");                                    
            strSql.Append(" ErHaoTongDaoTemp = @ErHaoTongDaoTemp , ");                                    
            strSql.Append(" SanHaoTongDaoTemp = @SanHaoTongDaoTemp , ");                                    
            strSql.Append(" ShaoJieCollectionID = @ShaoJieCollectionID , ");                                    
            strSql.Append(" LastUpdatedDate = @LastUpdatedDate , ");                                    
            strSql.Append(" LastUpdatedBy = @LastUpdatedBy  ");            			
			strSql.Append(" where ID=@ID ");
						
SqlParameter[] parameters = {
			            new SqlParameter("@ID", SqlDbType.BigInt,8) ,            
                        new SqlParameter("@ShaoJieYuXingDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@AXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@BXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@BXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CXiangDianYa", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CXiangDianLiu", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@YiHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ErHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@SanHaoTongDaoTemp", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShaoJieCollectionID", SqlDbType.BigInt,8) ,            
                        new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime) ,            
                        new SqlParameter("@LastUpdatedBy", SqlDbType.NVarChar,200)             
              
            };
						            
            parameters[0].Value = model.ID;                        
            parameters[1].Value = model.ShaoJieYuXingDate;                        
            parameters[2].Value = model.AXiangDianYa;                        
            parameters[3].Value = model.AXiangDianLiu;                        
            parameters[4].Value = model.BXiangDianYa;                        
            parameters[5].Value = model.BXiangDianLiu;                        
            parameters[6].Value = model.CXiangDianYa;                        
            parameters[7].Value = model.CXiangDianLiu;                        
            parameters[8].Value = model.YiHaoTongDaoTemp;                        
            parameters[9].Value = model.ErHaoTongDaoTemp;                        
            parameters[10].Value = model.SanHaoTongDaoTemp;                        
            parameters[11].Value = model.ShaoJieCollectionID;                        
            parameters[12].Value = model.LastUpdatedDate;                        
            parameters[13].Value = model.LastUpdatedBy;                        
            int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
		
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(long ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from PvZDShaoJieYunXing ");
			strSql.Append(" where ID=@ID");
						SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.BigInt)
			};
			parameters[0].Value = ID;


			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from PvZDShaoJieYunXing ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
				
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public PvZDShaoJieYunXing GetModel(long ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID, ShaoJieYuXingDate, AXiangDianYa, AXiangDianLiu, BXiangDianYa, BXiangDianLiu, CXiangDianYa, CXiangDianLiu, YiHaoTongDaoTemp, ErHaoTongDaoTemp, SanHaoTongDaoTemp, ShaoJieCollectionID, LastUpdatedDate, LastUpdatedBy  ");			
			strSql.Append("  from PvZDShaoJieYunXing ");
			strSql.Append(" where ID=@ID");
						SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.BigInt)
			};
			parameters[0].Value = ID;

			
			PvZDShaoJieYunXing model=new PvZDShaoJieYunXing();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			
			if(ds.Tables[0].Rows.Count>0)
			{
												if(ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ShaoJieYuXingDate"].ToString()!="")
				{
					model.ShaoJieYuXingDate=DateTime.Parse(ds.Tables[0].Rows[0]["ShaoJieYuXingDate"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["AXiangDianYa"].ToString()!="")
				{
					model.AXiangDianYa=decimal.Parse(ds.Tables[0].Rows[0]["AXiangDianYa"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["AXiangDianLiu"].ToString()!="")
				{
					model.AXiangDianLiu=decimal.Parse(ds.Tables[0].Rows[0]["AXiangDianLiu"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["BXiangDianYa"].ToString()!="")
				{
					model.BXiangDianYa=decimal.Parse(ds.Tables[0].Rows[0]["BXiangDianYa"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["BXiangDianLiu"].ToString()!="")
				{
					model.BXiangDianLiu=decimal.Parse(ds.Tables[0].Rows[0]["BXiangDianLiu"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CXiangDianYa"].ToString()!="")
				{
					model.CXiangDianYa=decimal.Parse(ds.Tables[0].Rows[0]["CXiangDianYa"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["CXiangDianLiu"].ToString()!="")
				{
					model.CXiangDianLiu=decimal.Parse(ds.Tables[0].Rows[0]["CXiangDianLiu"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["YiHaoTongDaoTemp"].ToString()!="")
				{
					model.YiHaoTongDaoTemp=decimal.Parse(ds.Tables[0].Rows[0]["YiHaoTongDaoTemp"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ErHaoTongDaoTemp"].ToString()!="")
				{
					model.ErHaoTongDaoTemp=decimal.Parse(ds.Tables[0].Rows[0]["ErHaoTongDaoTemp"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["SanHaoTongDaoTemp"].ToString()!="")
				{
					model.SanHaoTongDaoTemp=decimal.Parse(ds.Tables[0].Rows[0]["SanHaoTongDaoTemp"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["ShaoJieCollectionID"].ToString()!="")
				{
					model.ShaoJieCollectionID=long.Parse(ds.Tables[0].Rows[0]["ShaoJieCollectionID"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["LastUpdatedDate"].ToString()!="")
				{
					model.LastUpdatedDate=DateTime.Parse(ds.Tables[0].Rows[0]["LastUpdatedDate"].ToString());
				}
																																				model.LastUpdatedBy= ds.Tables[0].Rows[0]["LastUpdatedBy"].ToString();
																										
				return model;
			}
			else
			{
				return null;
			}
		}
		
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM PvZDShaoJieYunXing ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}
		
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" * ");
			strSql.Append(" FROM PvZDShaoJieYunXing ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}
		
		
		        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageIndex">从0开始</param>
        /// <param name="pageSize"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <returns></returns>
		public DataSet GetList(int pageIndex,int pageSize, string strWhere  = null,string filedOrder = null)
		{
			var startIndex = pageIndex * pageSize + 1;
			var endIndex = (pageIndex + 1) * pageSize;
			var totalCount = 0;
			
			var totalCountSqlBuilder = new StringBuilder();
			totalCountSqlBuilder.Append(" SELECT COUNT([ID]) FROM PvZDShaoJieYunXing ");
			if(!string.IsNullOrEmpty(strWhere))
			{
				totalCountSqlBuilder.Append(" where "+strWhere);
			}
			totalCount = (int)DbHelperSQL.GetSingle(totalCountSqlBuilder.ToString());
			
				StringBuilder strSql=new StringBuilder();
				strSql.Append("select TOP "+pageSize.ToString()+" t.* from ");
				strSql.Append("(select ");
				strSql.Append(" row_number() over (" );
				if(!string.IsNullOrEmpty(filedOrder))
				{
					strSql.Append(" order by " + filedOrder);
				}
				else 
				{
					strSql.Append(" ORDER BY [ID] ");
				}
				strSql.Append(") AS ___rownum, ");
				
				strSql.Append(" * ");
				strSql.Append(" FROM PvZDShaoJieYunXing ");
				if(!string.IsNullOrEmpty(strWhere))
				{
					strSql.Append(" where "+strWhere);
				}
				strSql.Append(") t ");
				strSql.Append(" where t.___rownum>="+startIndex.ToString()+" AND t.___rownum<="+endIndex.ToString());
				if(!string.IsNullOrEmpty(filedOrder))
				{
					strSql.Append(" order by " + filedOrder);
				}
				
				var dataSet = DbHelperSQL.Query(strSql.ToString());
					
            if (totalCount > 0 && startIndex <= totalCount)
			{		
				for(var i=1;i<startIndex;i++)
				{
					dataSet.Tables[0].Rows.InsertAt(dataSet.Tables[0].NewRow(),0);				
				}
				for(var i=endIndex;i<totalCount;i++)
				{
					dataSet.Tables[0].Rows.Add(dataSet.Tables[0].NewRow());
				}
			}
			return dataSet;
		}
				#endregion
   
   		#region IPVDomain
   		public string GetDbTableName()
   		{
   			return "PvZDShaoJieYunXing";
   		}
   		#endregion
	}
}

